﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Sharp.Infrastructure.Search
{
    //public interface IPagingFeature
    //{
    //    [DataMember]
    //    IList<PagingFeature.Filter> Filters { get; set; }

    //    [DataMember]
    //    string SimpleSort { get; set; }

    //    [DataMember]
    //    int PageNo { get; set; }

    //    [DataMember]
    //    int PageSize { get; set; }
    //}

    [DataContract]
    public class PagingFeature// : IPagingFeature
    {
        /// <summary>
        /// 根据不同数据列表初始化默认值
        /// </summary>
        /// <param name="engine"></param>
        public PagingFeature(UIEngine engine)
        {
            switch (engine)
            {
                case UIEngine.Ext:
                    //Filters = System.Web.HttpContext.Current.Request["filter"].FromJson<List<PagingFeature.Filter>>();
                    break;
            }
            if (Filters == null)
            {
                Filters = new List<SearchCondition>();
            }
            if (this.PageNo == 0)
                this.PageNo = 1;
            if (this.PageSize == 0)
                this.PageSize = 10;
            if (this.SimpleSort.IsNullOrEmpty())
                this.SimpleSort = "Id DESC";
        }
        /// <summary>
        /// 筛选数据
        /// </summary>
        [DataMember]
        public List<SearchCondition> Filters { get; set; }
        /// <summary>
        /// 排序字段
        /// </summary>
        [DataMember]
        public string SimpleSort { get; set; }
        /// <summary>
        /// 第几页
        /// </summary>
        [DataMember]
        public int PageNo { get; set; }
        /// <summary>
        /// 每页显示多少条数据
        /// </summary>
        [DataMember]
        public int PageSize { get; set; }
        /// <summary>
        /// 请求参数
        /// </summary>
        public NameValueCollection Request
        {
            get { return HttpUtility.ParseQueryString(RequestString); }
        }
        [DataMember]
        public string RequestString { get; set; }

        ///// <summary>
        ///// 筛选字段
        ///// </summary>
        //[DataContract]
        //public class Filter
        //{
        //    [DataMember(Name = "type")]
        //    public string Type { get; set; }
        //    [DataMember(Name = "field")]
        //    public string Field { get; set; }
        //    [DataMember(Name = "value")]
        //    public string Value { get; set; }
        //}
    }

    public enum UIEngine
    {
        /// <summary>
        /// 没有
        /// </summary>
        None = 0,
        /// <summary>
        /// Extjs/Ext.net
        /// </summary>
        Ext = 1,
        /// <summary>
        /// jQuery.DataTables
        /// </summary>
        DataTables = 2
    }
}
